package com.kaifamiao.N0822;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class Poker {

    // 花色
    private final List<String> colors = List.of("♠", "♥", "♦", "♣");
    // 牌面
    private final List<String> nums = List.of("A", "2", "3", "4", "5", "6", "7", "8", "9", "10","J", "Q", "K");
    // 大小王
    private final List<String> jokers = List.of("大王", "小王");

    private final List<String> pokers = new ArrayList<>();

    private void init(){
        for (String color: colors){
            for (String num : nums) {
                pokers.add(color + num);
            }
        }
        pokers.addAll(jokers);
    }

    public Poker(){
        init();
    }

    public List<String> getPokers(){
        return pokers;
    }

    public void shuffle(){
        Collections.shuffle(pokers);
    }

    @Override
    public String toString(){
        return pokers.toString();
    }
}


class PokerComparator implements Comparator<String> {
    // 牌的顺序
    private final List<String> order = List.of("大王", "小王", "2", "A", "K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3");
    @Override
    public int compare(String o1, String o2) {

        int index1 = order.indexOf(o1);
        int index2 = order.indexOf(o2);

        if (index1 == -1 && index2 == -1){
            // 两张牌都是 带花色的牌
            String num1 = o1.substring(1);
            String num2 = o2.substring(1);
            return order.indexOf(num1) - order.indexOf(num2);
        } else {
            // 有大小王
            if (index1 >= 0 && index2 >= 0){ // 两个分别是大王或小王
                return index1 - index2;
            } else if (index1 >= 0){
                return -1;
            } else {
                return 1;
            }
        }
    }
}
